<?php
      
class Request {
      private $name;
      private  $request;
      private $session;
      
            public function __construct($name,$session=null){
                 $this->name=$name;
                 $this->request=array();
                  $this->session=$session;
                  if($this->session==null)$this->makeRequest();
                  else   $this->makeSessionRequest();
            }
            
            
            
            public function printRequest(){
                  print_r($this->request);
            }
            
            
            private function compareToName($str){
                  $len=sizeof($this->name);
                        $str_cp=substr($str,0,$len);
                        if($str_cp==$this->name)return substr($str,$len+1,sizeof($str));
                        else return null; 
                              
            }
            
            private function  makeSessionRequest(){
                  $keys=array_keys($_REQUEST);
                  $this->request=$this->session->getRequest($this->name);
                        foreach($keys as $key){
                              $val=$this->compareToName($key);
                              if($val!=null)$this->request[$val]=$_REQUEST[$key];
                        }
                        $this->session->setRequest($this->name,$this->request);
            } 
            
            private function  makeRequest(){
                  $keys=array_keys($_REQUEST);
                        foreach($keys as $key){
                              $val=$this->compareToName($key);
                              if($val!=null)$this->request[$val]=$_REQUEST[$key];
                        }
            }
            
            public function getName(){                               
                  return $this->name;
            }
            
            public function getValue($key){                              
                  if($this->session!=null)$this->request=$this->session->getRequest($this->name);
                  return $this->request[$key];
            }
            
            
            public function setValue($key,$value){
                  $this->request[$key]=$value;
                  if($this->session!=null)$this->session->setRequest($this->name,$this->request);
            }
            
            public function getRequest(){
            if(sizeof($this->request)==0)return null;
                  return $this->request;
            }
            
            public function setRequest($req){
                  $this->request=$req;
            }
            
      
}

?>
